package com.smartcar.tcp;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * TCP消息处理器
 */
@Slf4j
@ChannelHandler.Sharable
public class TCPMessageHandler extends SimpleChannelInboundHandler<String> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) {
        log.info("收到TCP消息: {}", msg);
        // 这里可以添加消息处理逻辑
        // 比如解析小车返回的状态信息等
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        log.info("TCP连接已建立");
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) {
        log.info("TCP连接已断开");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        log.error("TCP连接异常", cause);
        ctx.close();
    }
} 